//
//  IntroTableViewCell.m
//  悦读
//
//  Created by dllo on 15/5/22.
//  Copyright (c) 2015年 贾建兴. All rights reserved.
//

#import "IntroTableViewCell.h"
#import <AFNetworking/UIImageView+AFNetworking.h>
#import "CollectClass.h"
@implementation IntroTableViewCell

- (void)dealloc
{
    [_authorLabel release];
    [_nameLabel release];
    [_typeLabel release];
    [_voiceButton release];
    [_showImage release];
    [_readButton release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return  self;
}


- (void)createView
{
    self.showImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 100, 150)];
    
    [self.contentView addSubview:_showImage];
    [_showImage release];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.showImage.frame.origin.x + self.showImage.frame.size.width + 10, self.showImage.frame.origin.y, 150, 40)];
    
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel release];
    
    
    self.typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height+ 20, 250, 30)];

    [self.contentView addSubview:self.typeLabel];
    [self.typeLabel release];
    
    
    self.readButton = [[UIButton alloc] initWithFrame:CGRectMake(self.nameLabel.frame.origin.x, self.typeLabel.frame.origin.y + self.typeLabel.frame.size.height + 25, 130, 30)];
    self.readButton.enabled = NO;
    [self.readButton setBackgroundColor:[UIColor brownColor]];
    [self.readButton setTitle:@"阅读本书" forState:UIControlStateNormal];
    [self.contentView addSubview:self.readButton];
    [self.readButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.readButton addTarget:self action:@selector(read) forControlEvents:UIControlEventTouchUpInside];
    [self.readButton release];
    
}

// 阅读按钮的点击事件
- (void)read{
    
    [self.delegate toRead];
    
    
   
    
}
- (void)getDataWithDic:(NSDictionary *)dic array:(NSArray *)array
{
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"loading.gif" ofType:nil];
    
    [self.showImage setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"imageUrl"]] placeholderImage:[UIImage imageWithContentsOfFile:path]];
    self.nameLabel.text = [dic objectForKey:@"bookName"];
    self.bookId = [dic objectForKey:@"bookid"];
//    NSMutableString *str = [[array firstObject] objectForKey:@"catName"];
    
    NSMutableString *str = [NSMutableString string];
    for (int i = 0; i < array.count; i++) {
        
        NSMutableDictionary *dic = array[i];
        [str appendString:[dic objectForKey:@"catName"]];
        [str appendString:@" "];
    }
    
    self.typeLabel.text = str;
    self.authorLabel.text = [dic objectForKey:@"author"];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
